import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const key = 'user'

export default new Vuex.Store({
  state: {
    user: null,
    forumId: '',
     
  },
  getters: {
    getStorage: function(state) {
      if(!state.user) {
        state.user = JSON.parse(localStorage.getItem(key))
      }
      return state.user
    }
  },
  mutations: {
    setStorage: function(state, value) {
      state.user = value
      localStorage.setItem(key, JSON.stringify(value))
    },
    removeStorage: function(state) {
      state.user = null
      localStorage.removeItem(key)
    },
    setForumId: function(state, value) {
      state.forumId = value;
    }
  }

})